package com.hue.entity;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

/*
    发送邮件的工具
 */
@Component
public class EmailUtils {
    @Autowired
    private JavaMailSender javaMailSender;
    //邮件发送者
    @Value("${spring.mail.username}")
    private String from;

    /**
     *
     * @param to：接收者
     * @param subject:标题
     * @param text:内容
     */
    public void sendEmail(String to,String subject,String text){
        //创建一封简单邮件
        SimpleMailMessage email = new SimpleMailMessage();
        email.setFrom(from);
        email.setTo(to);
        email.setSubject(subject);
        email.setText(text);
        //通过javaMailSender发送邮件
        javaMailSender.send(email);
    }


}
